# https://leetcode.cn/problems/n-ary-tree-level-order-traversal/description/

from collections import deque


class Node:
    def __init__(self, val: int = None, children: list['Node'] = None):
        self.val = val
        self.children = children


class Solution:
    def levelOrder(self, root: Node) -> list[list[int]]:
        if root is None:
            return []
        res: list[list[int]] = []
        pt: deque[Node] = deque([root])
        while pt:
            res.append([])
            ptSize = len(pt)
            for _ in range(ptSize):
                node = pt.popleft()
                res[-1].append(node.val)
                for nextNode in node.children:
                    pt.append(nextNode)
        return res
